home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / dskut / dcopy332.zip / DCDCOPY.C next >
C/C++ Source or Header  |  1990-04-14  |  3KB  |  83 lines

  1. /*************************************************************
  2.  *                                                           *
  3.  * Program DCOPY - physical sector to sector copy              *
  4.  * Copyright (c) 1986 Joerg Genius, Munich, West-Germany     *
  5.  *                                                           *
  6.  * Rev. 3.1.1 fixed verify by supplying length to memcpy()   *
  7.  * Rev. 3.1.2 added /r command to verify only                *
  8.  * Rev. 3.3.0 added support for 3.5" disks                   *
  9.  *************************************************************/
  10.  
  11. #include <stdio.h>
  12. #include <alloc.h>
  13. #include <sys\types.h>
  14. #include <sys\stat.h>
  15. #include <io.h>
  16. #include "dcdefs.h"
  17.  
  18.  
  19. dcopy (von,nach,verify)
  20.  
  21. int von,nach,verify;
  22.  
  23. {
  24.    struct drive_data source,destination;
  25.  
  26.    char *ver_buffer;
  27.    unsigned int blcnt=0;
  28.    unsigned int max_blocks;
  29.    int error;
  30.  
  31.    if (verify!=0) {
  32.       if ((ver_buffer=malloc(512*blk_p_buffer))==NULL) {
  33.          fprintf (stderr,text[2]);
  34.          return 1;
  35.       }
  36.    }
  37.    if (get_drive_data(von,&source)!=0)
  38.       return 1;
  39.    if (get_drive_data(nach,&destination)!=0)
  40.       return 1;
  41.    if (source.cluster_p_drive!=destination.cluster_p_drive ||
  42.        source.sec_p_cluster  !=destination.sec_p_cluster   ||
  43.        source.bytes_p_sec     !=destination.bytes_p_sec) {
  44.       fprintf (stderr,text[14]);
  45.       return 1;
  46.    }
  47.    max_blocks=get_max_blocks(source.sec_p_drive);
  48.    printf (text[8],d_types[disk_type]);
  49.    if (verify!=2)
  50.       printf (text[15],source.sec_p_drive,von+'A',nach+'A');
  51.    else
  52.       printf (text[26],source.sec_p_drive,von+'A',nach+'A');
  53.    for (blcnt=0;blcnt<source.sec_p_drive;blcnt+=max_blocks) {
  54.       max_blocks=(blcnt+max_blocks>=source.sec_p_drive ? source.sec_p_drive-blcnt : max_blocks);
  55.       if ((error=read_block(von,blcnt,max_blocks,disk_buffer))!=0) {
  56.            fprintf (stderr,text[10],error,err_text[error]);
  57.            return 1;
  58.       }
  59.       if (verify!=2) {
  60.          if ((error=write_block(nach,blcnt,max_blocks,disk_buffer))!=0) {
  61.             fprintf (stderr,text[16],error,err_text[error]);
  62.             return 1;
  63.          }
  64.       }
  65.       if (verify!=0) {
  66.          if ((error=read_block(nach,blcnt,max_blocks,ver_buffer))!=0) {
  67.             fprintf (stderr,text[17],error,err_text[error]);
  68.             return 1;
  69.          }
  70.          if (memcmp(disk_buffer,ver_buffer,512*max_blocks)!=0) {
  71.             fprintf (stderr,text[18]);
  72.             return 1;
  73.          }
  74.       }
  75.    }
  76.    if (verify!=2)
  77.       printf (text[19],source.sec_p_drive,von+'A',nach+'A');
  78.    else
  79.       printf (text[27],source.sec_p_drive,von+'A',nach+'A');
  80.    return 0;
  81. }
  82.  
  83.